package com.cyou.nad.dao;

import java.io.Serializable;


@SuppressWarnings("serial")
public  class AbstractPagination implements Pagination,Serializable{
	
	protected int pageSize = DEFAULT_PAGE_SIZE; // 每页的记录数

	protected int start; // 当前页第一条数据在List中的位置,从0开始

	protected int totalCount; // 总记录数


	/**
	 * 取该页当前页码,页码从1开始.
	 */
	public int getCurrentPageNo() {
		return start / pageSize + 1;
	}

	

	/**
	 * 取每页数据容量.
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * 取总记录数.
	 */
	public int getTotalCount() {
		return totalCount;
	}

	/**
	 * 取总页数.
	 */
	public int getTotalPageCount() {
		if (totalCount % pageSize == 0)
			return totalCount / pageSize;
		else
			return totalCount / pageSize + 1;
	}

	/**
	 * 该页是否有下一页.
	 */
	public boolean hasNextPage() {
		return getCurrentPageNo() < getTotalPageCount() - 1;
	}

	/**
	 * 该页是否有上一页.
	 */
	public boolean hasPreviousPage() {
		return getCurrentPageNo() > 1;
	}


	public Integer getTotal() {
		return getTotalCount();
	}


	public void setTotal(Integer total) {
		this.totalCount = total;
	}
}
